use godot::{classes::Control, prelude::*};


#[derive(GodotClass)]
#[class(init, base=Node)]
pub struct VisualEffectHub {
	#[export]
	effect2d_root: Option<Gd<Node2D>>,
	#[export]
	effect3d_root: Option<Gd<Node3D>>,
	#[export]
	ui_effect_root: Option<Gd<Control>>,
}

#[godot_api]
impl VisualEffectHub {
	#[func]
	pub fn add_effect2d(&mut self, mut effect: Gd<Node2D>) {
		if let Some(root) = &mut self.effect2d_root {
			root.add_child(&effect);
		} else {
			godot_error!("effect2d root is null");
			effect.queue_free();
		}
	}

	#[func]
	pub fn add_effect3d(&mut self, mut effect: Gd<Node3D>) {
		if let Some(root) = &mut self.effect3d_root {
			root.add_child(&effect);
		} else {
			godot_error!("effect3d root is null");
			effect.queue_free();
		}
	}

	#[func]
	pub fn add_ui_effect(&mut self, mut effect: Gd<Control>) {
		if let Some(root) = &mut self.ui_effect_root {
			root.add_child(&effect);
		} else {
			godot_error!("ui effect root is null");
			effect.queue_free();
		}
	}
}